package com.supms.patrol.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.supms.patrol.domain.DailyInspection;
import com.supms.patrol.service.IDailyInspectionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 日常巡查记录Controller
 * 
 * @author LiangHao
 * @date 2022-03-14
 */
@RestController
@RequestMapping("/dailyInspection")
public class DailyInspectionController extends BaseController
{
    @Autowired
    private IDailyInspectionService dailyInspectionService;

    /**
     * 查询日常巡查记录列表
     */
    @RequiresPermissions("patrol:dailyInspection:list")
    @GetMapping("/list")
    public TableDataInfo list(DailyInspection dailyInspection)
    {
        startPage();
        List<DailyInspection> list = dailyInspectionService.selectDailyInspectionList(dailyInspection);
        return getDataTable(list);
    }

    /**
     * 导出日常巡查记录列表
     */
    @RequiresPermissions("patrol:dailyInspection:export")
    @Log(title = "日常巡查记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DailyInspection dailyInspection)
    {
        List<DailyInspection> list = dailyInspectionService.selectDailyInspectionList(dailyInspection);
        ExcelUtil<DailyInspection> util = new ExcelUtil<DailyInspection>(DailyInspection.class);
        util.exportExcel(response, list, "日常巡查记录数据");
    }

    /**
     * 获取日常巡查记录详细信息
     */
    @RequiresPermissions("patrol:dailyInspection:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dailyInspectionService.selectDailyInspectionById(id));
    }

    /**
     * 新增日常巡查记录
     */
    @RequiresPermissions("patrol:dailyInspection:add")
    @Log(title = "日常巡查记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DailyInspection dailyInspection)
    {
        return toAjax(dailyInspectionService.insertDailyInspection(dailyInspection));
    }

    /**
     * 修改日常巡查记录
     */
    @RequiresPermissions("patrol:dailyInspection:edit")
    @Log(title = "日常巡查记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DailyInspection dailyInspection)
    {
        return toAjax(dailyInspectionService.updateDailyInspection(dailyInspection));
    }

    /**
     * 删除日常巡查记录
     */
    @RequiresPermissions("patrol:dailyInspection:remove")
    @Log(title = "日常巡查记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        int i = dailyInspectionService.deleteDailyInspectionByIds(ids);
        if (i == 5000) {
            return error("删除失败！当前巡查表下有提前下课情况记录。");
        } else return toAjax(i);
    }

    /**
     * 获取日常巡查记录表（数据综合查看表）
     */
    @GetMapping("/getDailyInspectionTable")
    public DailyInspection getDailyInspectionTable(DailyInspection dailyInspection)
    {
        return dailyInspectionService.getDailyInspectionTable(dailyInspection);
    }
}
